clear all
set more off
global src_folder "<Set PATH>"
cd "$src_folder"

use rcfs_main

global covar "ln_pred_nfs_atmcount_pc_pd ln_pred_pos_terminalcount_pc_pd dist_vurban_pd ln_imp_pin_branch_pc_pd sh_natl_dep_amt16_pd sh_natl_dep_ac16_pd ln_imp_pop_pin_pd pin_cc_map_pd"
global covarpc "pred_nfs_atmcount_pc_pd pred_pos_terminalcount_pc_pd dist_vurban_pd imp_pin_branch_pc_pd sh_natl_dep_amt16_pd sh_natl_dep_ac16_pd pin_cc_map_pd"

global hetbranch "dist_cc_pnt dist_cc_plt high_branch_pnt high_branch_plt dist_cc_branch_pnt dist_cc_branch_plt"
global hetpos "dist_cc_pnt dist_cc_plt high_pos_pnt high_pos_plt dist_cc_pos_pnt dist_cc_pos_plt"
global hetatm "dist_cc_pnt dist_cc_plt high_atm_pnt high_atm_plt dist_cc_atm_pnt dist_cc_atm_plt"

global hetdbranch "dist_cc_pnt dist_cc_plt distcc_high_dbranch_pnt distcc_high_dbranch_plt"	
global hetdpos "dist_cc_pnt dist_cc_plt distcc_dhpos_pnt distcc_dhpos_plt"
global hetdatm "dist_cc_pnt dist_cc_plt distcc_dhatm_pnt distcc_dhatm_plt"

global hetrural "dist_cc_pnt dist_cc_plt rural_pnt rural_plt dist_cc_rural_pnt dist_cc_rural_plt"
global hetdrural "dist_cc_pnt dist_cc_plt distcc_high_rural_pnt distcc_high_rural_plt"	
global hetdinformal "dist_cc_pnt dist_cc_plt distcc_high_informal_pnt distcc_high_informal_plt"	
global hetdself "dist_cc_pnt dist_cc_plt distcc_high_self_pnt distcc_high_self_plt"	

global hhighway "dist_cc_pnt dist_cc_plt distcc_high_highway_pnt distcc_high_highway_plt"	
global hbus "dist_cc_pnt dist_cc_plt distcc_high_bus_pnt distcc_high_bus_plt"	
global htaxi "dist_cc_pnt dist_cc_plt distcc_high_taxi_pnt distcc_high_taxi_plt"	

global eventpcovar "distcc_t0 distcc_pt1 distcc_pt2 distcc_pt3 distcc_pt4 distcc_pt5"   
global eventncovar "distcc_nt2 distcc_nt3"   

global indexm "dist_cc_pnt dist_cc_plt avg_zip_fin_infra_pc_pnt avg_zip_fin_infra_pc_plt distcc_avg_zip_fin_infra_pc_pnt distcc_avg_zip_fin_infra_pc_plt" 
global index1 "distcc_std_hh_fin_incl_pnt distcc_std_hh_fin_incl_plt distcc_std_inf_formal_pnt distcc_std_inf_formal_plt" 
global index2 "distcc_std_phy_infra_pnt distcc_std_phy_infra_plt distcc_std_educ_pnt distcc_std_educ_plt" 
global index3 "distcc_std_aware_pnt distcc_std_aware_plt distcc_std_trust_pnt distcc_std_trust_plt distcc_std_network2_pnt distcc_std_network2_plt" 
global index4 "distcc_std_informal_pnt distcc_std_informal_plt distcc_std_mpce30_pnt distcc_std_mpce30_plt" 

*Main Sample is for DistCC <= 40km
gen isample = 0
replace isample = 1 if dist_cc <= 40

*Regression to predict residuals so that regression without covariates only includes pincodes for which covariates are present
reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt $covar if isample == 1, absorb(pincode dist_qtr_yr, savefe) cluster(pincode) tolerance(0.00001) maxiterations(100000) resid
predict r1, residuals

reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt $covar if isample == 1, absorb(pincode dist_qtr_yr, savefe) cluster(pincode) tolerance(0.00001) maxiterations(100000) resid
predict r2, residuals

*Table 1: Cash Supply Shock, Cash Withdrawals and Digital Payments
global coefint "dist_cc_pnt dist_cc_plt hdist_pnt hdist_plt dist_cc1_pnt dist_cc1_plt dist_cc2_pnt dist_cc2_plt dist_cc3_pnt dist_cc3_plt dist_cc4_pnt dist_cc4_plt dist_cc5_pnt dist_cc5_plt"

eststo clear
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt if isample == 1 & r1 != ., absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount hdist_pnt hdist_plt $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount dist_cc2_pnt dist_cc2_plt dist_cc3_pnt dist_cc3_plt dist_cc4_pnt dist_cc4_plt dist_cc5_pnt dist_cc5_plt $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt if isample == 1 & r2 != ., absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount hdist_pnt hdist_plt $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc2_pnt dist_cc2_plt dist_cc3_pnt dist_cc3_plt dist_cc4_pnt dist_cc4_plt dist_cc5_pnt dist_cc5_plt $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)

esttab, ar2 se(3) b(3)  star(* 0.10 ** 0.05 *** 0.01) keep($coefint) /// 
	nonotes fragment label mtitles("\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}") ///
	order($coefint)
	
*Table 2: Robustness to Alternate Samples

global coefint "dist_cc_pnt dist_cc_plt"	
eststo clear
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt $covar, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt $covar if isample == 1 & dist_cc != 0, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt $covar if isample == 1 & metro == 0, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt $covar if isample == 1 & qtr_yr <= 6, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt $covar, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt $covar if isample == 1 & dist_cc != 0, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt $covar if isample == 1 & metro == 0, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt $covar if isample == 1 & qtr_yr <= 6, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)

esttab, ar2 se(3) b(3)  star(* 0.10 ** 0.05 *** 0.01) keep($coefint) /// 
	nonotes fragment label mtitles("\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}") ///
	order($coefint)
	
*Table 3: Heterogeneity in Digital Payments by Local Financial Infrastructure
global coefint "dist_cc_pnt dist_cc_plt dist_cc_pos_pnt dist_cc_pos_plt dist_cc_branch_pnt dist_cc_branch_plt dist_cc_atm_pnt dist_cc_atm_plt distcc_avg_zip_fin_infra_pc_pnt distcc_avg_zip_fin_infra_pc_plt distcc_dhpos_pnt distcc_dhpos_plt distcc_high_dbranch_pnt distcc_high_dbranch_plt distcc_dhatm_pnt distcc_dhatm_plt"		

eststo clear
eststo: quietly reghdfe ln_pos_totalamount $hetpos $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount $hetbranch $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount $hetatm $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount $hetdpos $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount $hetdbranch $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount $hetdatm $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)

esttab, ar2 se(3) b(3)  star(* 0.10 ** 0.05 *** 0.01) keep($coefint) /// 
	nonotes fragment label mtitles("\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}") ///
	order($coefint)
	
*Table 4: Heterogeneity by Regional Characteristics

global coefint "dist_cc_pnt dist_cc_plt distcc_avg_zip_fin_infra_pc_pnt distcc_avg_zip_fin_infra_pc_plt distcc_std_hh_fin_incl_pnt distcc_std_hh_fin_incl_plt distcc_std_inf_formal_pnt distcc_std_inf_formal_plt distcc_std_educ_infra_pnt distcc_std_educ_infra_plt distcc_std_phy_infra_pnt distcc_std_phy_infra_plt distcc_std_educ_pnt distcc_std_educ_plt distcc_std_aware_pnt distcc_std_aware_plt distcc_std_trust_pnt distcc_std_trust_plt distcc_std_network2_pnt distcc_std_network2_plt distcc_std_informal_pnt distcc_std_informal_plt"   

eststo clear	
eststo: quietly reghdfe ln_pos_totalamount $indexm $index1 $index2 $index3 $index4 $covar if isample == 1 , absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_transcount $indexm $index1 $index2 $index3 $index4 $covar if isample == 1 , absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)

esttab, ar2 se(3) b(3)  star(* 0.10 ** 0.05 *** 0.01) keep($coefint) /// 
	nonotes fragment label mtitles("\shortstack{POS\\Vol}" "\shortstack{POS\\Count}" ) ///
	order($coefint)
	
*Appendix Table D1: Heterogeneity in Digital Transactions by Regional Informality
global coefint "dist_cc_pnt dist_cc_plt dist_cc_rural_pnt dist_cc_rural_plt distcc_high_rural_pnt distcc_high_rural_plt distcc_high_informal_pnt distcc_high_informal_plt distcc_high_self_pnt distcc_high_self_plt"		
eststo clear
eststo: quietly reghdfe ln_pos_totalamount $hetrural $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount $hetdrural $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount $hetdinformal $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount $hetdself $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)

esttab, ar2 se(3) b(3)  star(* 0.10 ** 0.05 *** 0.01) keep($coefint) /// 
	nonotes fragment label mtitles("\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}") ///
	order($coefint)
	
*Appendix Table D2: Heterogeneity in Cash Withdrawals by Regional Informality
eststo clear
eststo: quietly reghdfe ln_nfs_totalamount $hetrural $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount $hetdrural $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount $hetdinformal $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount $hetdself $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)

esttab, ar2 se(3) b(3)  star(* 0.10 ** 0.05 *** 0.01) keep($coefint) /// 
	nonotes fragment label mtitles("\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}") ///
	order($coefint)
	
*Appendix Table D3: Heterogeneity in Digital Payments by Informality: Conditional on Corruption

global coefint "dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt" 

eststo clear
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt $covar if isample == 1 & hc_agg == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt $covar if isample == 1 & hc_agg == 0, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt $covar if isample == 1 & hc_bank == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt $covar if isample == 1 & hc_bank == 0, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt $covar if isample == 1 & hc_police == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt $covar if isample == 1 & hc_police == 0, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt $covar if isample == 1 & (hc_land == 1 | hc_house == 1), absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt $covar if isample == 1 & hc_land == 0 & hc_house == 0, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)

esttab, ar2 se(3) b(3)  star(* 0.10 ** 0.05 *** 0.01) keep($coefint) /// 
	nonotes fragment label mtitles("\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}") ///
	order($coefint)
	
*Appendix Table D3: Heterogeneity in Cash Withdrawals by Informality: Conditional on Corruption

eststo clear
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt $covar if isample == 1 & hc_agg == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt $covar if isample == 1 & hc_agg == 0, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt $covar if isample == 1 & hc_bank == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt $covar if isample == 1 & hc_bank == 0, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt $covar if isample == 1 & hc_police == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt $covar if isample == 1 & hc_police == 0, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt $covar if isample == 1 & (hc_land == 1 | hc_house == 1), absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt $covar if isample == 1 & hc_land == 0 & hc_house == 0, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)

esttab, ar2 se(3) b(3)  star(* 0.10 ** 0.05 *** 0.01) keep($coefint) /// 
	nonotes fragment label mtitles("\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}") ///
	order($coefint)
	
*Appendix Table D5: Heterogeneity in Digital Payments and Cash Withdrawal: Conditional on Financial Infrastructure	
	
global coefint "dist_cc_pnt dist_cc_plt distcc_std_informal_pnt distcc_std_informal_plt"   
eststo clear	
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt $index1 $index2 $index3 $index4 $covar if isample == 1 & avg_zip_fin_infra_pc <= -.3177265 , absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt $index1 $index2 $index3 $index4 $covar if isample == 1 & avg_zip_fin_infra_pc > -.3177265 & avg_zip_fin_infra_pc <= .0346756 , absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt $index1 $index2 $index3 $index4 $covar if isample == 1 & avg_zip_fin_infra_pc > .0346756 , absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)

eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt $index1 $index2 $index3 $index4 $covar if isample == 1 & avg_zip_fin_infra_pc <= -.3177265 , absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt $index1 $index2 $index3 $index4 $covar if isample == 1 & avg_zip_fin_infra_pc > -.3177265 & avg_zip_fin_infra_pc <= .0346756 , absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt $index1 $index2 $index3 $index4 $covar if isample == 1 & avg_zip_fin_infra_pc > .0346756 , absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)

esttab, ar2 se(3) b(3)  star(* 0.10 ** 0.05 *** 0.01) keep($coefint) /// 
	nonotes fragment label mtitles("\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}") ///
	order($coefint)
	
*Appendix Table E3: Heterogeneity by Regional Connectivity

global coefint "dist_cc_pnt dist_cc_plt distcc_high_highway_pnt distcc_high_highway_plt distcc_high_bus_pnt distcc_high_bus_plt distcc_high_taxi_pnt distcc_high_taxi_plt"

eststo clear
eststo: quietly reghdfe ln_nfs_totalamount $hhighway $covar if isample == 1 , absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount $hbus $covar if isample == 1 , absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount $htaxi $covar if isample == 1 , absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount $hhighway $covar if isample == 1 , absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount $hbus $covar if isample == 1 , absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount $htaxi $covar if isample == 1 , absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)

esttab, ar2 se(3) b(3)  star(* 0.10 ** 0.05 *** 0.01) keep($coefint) /// 
	nonotes fragment label mtitles("\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}") ///
	order($coefint)
	
*Appendix Table E4: Robustness to Alternate Specification Choices
	 		
global coefint "dist_cc_pnt dist_cc_plt dist_ccap1_pnt dist_ccap1_plt dist_ccap2_pnt dist_ccap2_plt dist_ccap3_pnt dist_ccap3_plt dist_ccap4_pnt dist_ccap4_plt dist_ccap5_pnt dist_ccap5_plt" 
eststo clear
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt $covar ln_nfs_totalamount_jt if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount dist_cc_pnt dist_cc_plt $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(dist_code) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount dist_ccap1_pnt dist_ccap1_plt dist_ccap2_pnt dist_ccap2_plt dist_ccap3_pnt dist_ccap3_plt dist_ccap4_pnt dist_ccap4_plt dist_ccap5_pnt dist_ccap5_plt $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt $covar ln_pos_totalamount_jt if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_cc_pnt dist_cc_plt $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(dist_code) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount dist_ccap1_pnt dist_ccap1_plt dist_ccap2_pnt dist_ccap2_plt dist_ccap3_pnt dist_ccap3_plt dist_ccap4_pnt dist_ccap4_plt dist_ccap5_pnt dist_ccap5_plt $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)

esttab, ar2 se(3) b(3)  star(* 0.10 ** 0.05 *** 0.01) keep($coefint) /// 
	nonotes fragment label mtitles("\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}" "\shortstack{POS\\Vol}") ///
	order($coefint)
	
*Appendix Table E5: Robustness to Alternate Outcome Variables

global coefint "dist_cc_pnt dist_cc_plt"	
eststo clear
eststo: quietly reghdfe ln_nfs_totalamount_pc dist_cc_pnt dist_cc_plt $covarpc if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_totalamount_pc dist_cc_pnt dist_cc_plt $covarpc if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ihs_nfs_totalamount dist_cc_pnt dist_cc_plt $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ihs_pos_totalamount dist_cc_pnt dist_cc_plt $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_transcount dist_cc_pnt dist_cc_plt $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_pos_transcount dist_cc_pnt dist_cc_plt $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)

esttab, ar2 se(3) b(3)  star(* 0.10 ** 0.05 *** 0.01) keep($coefint) /// 
	nonotes fragment label mtitles("\shortstack{ATM\\Vol\\Per Capita}" "\shortstack{POS\\Vol\\Per Capita}" "\shortstack{ATM\\Vol\\Inverse Hyperbolic Sine}" "\shortstack{ATM\\Vol\\Inverse Hyperbolic Sine}" "\shortstack{ATM\\Count}" "\shortstack{POS\\Count}") ///
	order($coefint)
	
*Appendix Table E7: Heterogeneity in Cash Withdrawals Financial Infrastructure
global coefint "dist_cc_pnt dist_cc_plt dist_cc_pos_pnt dist_cc_pos_plt dist_cc_branch_pnt dist_cc_branch_plt dist_cc_atm_pnt dist_cc_atm_plt distcc_avg_zip_fin_infra_pc_pnt distcc_avg_zip_fin_infra_pc_plt distcc_dhpos_pnt distcc_dhpos_plt distcc_high_dbranch_pnt distcc_high_dbranch_plt distcc_dhatm_pnt distcc_dhatm_plt"		
eststo clear
eststo: quietly  reghdfe ln_nfs_totalamount $hetpos $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount $hetbranch $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount $hetatm $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount $hetdpos $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount $hetdbranch $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
eststo: quietly reghdfe ln_nfs_totalamount $hetdatm $covar if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)

esttab, ar2 se(3) b(3)  star(* 0.10 ** 0.05 *** 0.01) keep($coefint) /// 
	nonotes fragment label mtitles("\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}" "\shortstack{ATM\\Vol}") ///
	order($coefint)
		
*Figure 5: Event Study Plot
quietly reghdfe ln_nfs_totalamount $eventpcovar $eventncovar $covar  if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
parmest, label list(parm label estimate min* max* p) saving("atm_vol_level_did", replace)
quietly reghdfe ln_pos_totalamount $eventpcovar $eventncovar $covar  if isample == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
parmest, label list(parm label estimate min* max* p) saving("pos_vol_level_did", replace)

*Figure 8: Event Study Plot, Sub-Samples by Financial Infrastructure and Awareness
quietly reghdfe ln_pos_totalamount $eventpcovar $eventncovar $covar if dist_cc <= 40 & avg_zip_fin_infra_pc <= -.1958422 & high_aware == 0, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
parmest, label list(parm label estimate min* max* p) saving("pos_vol_level_low_infra_low_aware_did", replace)

quietly reghdfe ln_pos_totalamount $eventpcovar $eventncovar $covar if dist_cc <= 40 & avg_zip_fin_infra_pc <= -.1958422 & high_aware == 1, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
parmest, label list(parm label estimate min* max* p) saving("pos_vol_level_low_infra_high_aware_did", replace)

quietly reghdfe ln_pos_totalamount $eventpcovar $eventncovar $covar if dist_cc <= 40 & avg_zip_fin_infra_pc > -.1958422 & high_aware == 0 & avg_zip_fin_infra_pc != ., absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
parmest, label list(parm label estimate min* max* p) saving("pos_vol_level_high_infra_low_aware_did", replace)

quietly reghdfe ln_pos_totalamount $eventpcovar $eventncovar $covar if dist_cc <= 40 & avg_zip_fin_infra_pc > -.1958422 & high_aware == 1 & avg_zip_fin_infra_pc != ., absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
parmest, label list(parm label estimate min* max* p) saving("pos_vol_level_high_infra_high_aware_did", replace)


*Figure E7
quietly reghdfe ln_pos_terminalcount_pc $eventpcovar $eventncovar $covar if dist_cc <= 40, absorb(pincode dist_qtr_yr) cluster(pincode) tolerance(0.00001) maxiterations(100000)
parmest, label list(parm label estimate min* max* p) saving("pos_terminal_did", replace)


*Figure 2: Distribution of Distance to Currency Chests (One pincode observation only)
duplicates drop pincode, force
kdensity dist_cc if dist_cc <= 40, graphregion(color(white)) xtitle("Distance to Currency Chest (km)", height(5)) title("")

*Create Event Study Plots
*Figure 5: Cash Withdrawals
clear all
use atm_vol_level_did, clear

set obs `= _N + 1'
replace parm = "distcc_nt1" if parm == ""
replace label = "t = 0" if strpos(parm, "t0")
replace label = "1" if parm == "distcc_nt1"
replace label = "-" + label if strpos(parm, "nt")
foreach var of varlist estimate stderr min95 max95 { 
replace `var' = 0 if `var' == .
}

replace label = "0" if label == "t = 0"
destring label, force replace 
drop if label == .
sort label

*line estimate min95 max95 label, lpattern(l - - ) xline(0) yline(0)
*encode parm, generate(parm2)
*drop parm
*rename parm2 parm
label variable estimate "Demonetization Effect"
label variable min95 "Lower CI 95pc"
label variable max95 "Upper CI 95pc" 

twoway (connected estimate label, graphregion(color(white)) lc(navy) mc(navy)) ///
(rline min95 max95 label, lpattern(dot) lcolor(blue)), yline(0, lcolor(red)) ///
xline(-1, lcolor(solid) lpattern(dash)) xlabel(-3 0 3 6) ylabel(#3) ///
xtitle("") ytitle("Percent", height(5)) legend(off) ///
ylab(, nogrid) xlab(, nogrid) graphregion(margin(2 2 2 2)) subtitle("Cash Withdrawals")

graph save atm_vol_level_did.gph, replace
graph export atm_vol_level_did.png, replace


*Figure 5: Digital Payments
use pos_vol_level_did, clear

set obs `= _N + 1'
replace parm = "distcc_nt1" if parm == ""
replace label = "t = 0" if strpos(parm, "t0")
replace label = "1" if parm == "distcc_nt1"
replace label = "-" + label if strpos(parm, "nt")
foreach var of varlist estimate stderr min95 max95 { 
replace `var' = 0 if `var' == .
}

replace label = "0" if label == "t = 0"
destring label, force replace 
drop if label == .
sort label

*line estimate min95 max95 label, lpattern(l - - ) xline(0) yline(0)
*encode parm, generate(parm2)
*drop parm
*rename parm2 parm
label variable estimate "Demonetization Effect"
label variable min95 "Lower CI 95pc"
label variable max95 "Upper CI 95pc" 

twoway (connected estimate label, graphregion(color(white)) lc(navy) mc(navy)) ///
(rline min95 max95 label, lpattern(dot) lcolor(blue)), yline(0, lcolor(red)) ///
xline(-1, lcolor(solid) lpattern(dash)) xlabel(-3 0 3 6) ///
xtitle("") ytitle("Percent", height(5)) legend(off) ///
ylab(, nogrid) xlab(, nogrid) graphregion(margin(2 2 2 2)) subtitle("Digital Transactions")

graph save pos_vol_level_did.gph, replace
graph export pos_vol_level_did.png, replace

*Figure 8

*Figure 8, Low Infrastructure, Low Awareness
clear all
use pos_vol_level_low_infra_low_aware_did, clear

set obs `= _N + 1'
replace parm = "distcc_nt1" if parm == ""
replace label = "t = 0" if strpos(parm, "t0")
replace label = "1" if parm == "distcc_nt1"
replace label = "-" + label if strpos(parm, "nt")
foreach var of varlist estimate stderr min95 max95 { 
replace `var' = 0 if `var' == .
}

replace label = "0" if label == "t = 0"
destring label, force replace 
drop if label == .
sort label

*line estimate min95 max95 label, lpattern(l - - ) xline(0) yline(0)
*encode parm, generate(parm2)
*drop parm
*rename parm2 parm
label variable estimate "Demonetization Effect"
label variable min95 "Lower CI 95pc"
label variable max95 "Upper CI 95pc" 

twoway (connected estimate label, graphregion(color(white)) lc(navy) mc(navy)) ///
(rline min95 max95 label, lpattern(dot) lcolor(blue)), yline(0, lcolor(red)) ///
xline(-1, lcolor(solid) lpattern(dash)) xlabel(-3 0 3 6) ylabel(#3) ///
xtitle("") ytitle("Percent", height(5)) legend(off) ///
ylab(, nogrid) xlab(, nogrid) graphregion(margin(2 2 2 2)) subtitle("Low Infrastructure" "Low Awareness")

graph save pos_vol_level_low_infra_low_aware_did.gph, replace


*Figure 8, Low Infrastructure, High Awareness
clear all
use pos_vol_level_low_infra_high_aware_did, clear

set obs `= _N + 1'
replace parm = "distcc_nt1" if parm == ""
replace label = "t = 0" if strpos(parm, "t0")
replace label = "1" if parm == "distcc_nt1"
replace label = "-" + label if strpos(parm, "nt")
foreach var of varlist estimate stderr min95 max95 { 
replace `var' = 0 if `var' == .
}

replace label = "0" if label == "t = 0"
destring label, force replace 
drop if label == .
sort label

label variable estimate "Demonetization Effect"
label variable min95 "Lower CI 95pc"
label variable max95 "Upper CI 95pc" 

twoway (connected estimate label, graphregion(color(white)) lc(navy) mc(navy)) ///
(rline min95 max95 label, lpattern(dot) lcolor(blue)), yline(0, lcolor(red)) ///
xline(-1, lcolor(solid) lpattern(dash)) xlabel(-3 0 3 6) ylabel(#3) ///
xtitle("") ytitle("Percent", height(5)) legend(off) ///
ylab(, nogrid) xlab(, nogrid) graphregion(margin(2 2 2 2)) subtitle("Low Infrastructure" "High Awareness")

graph save pos_vol_level_low_infra_high_aware_did.gph, replace


*Figure 8, High Infrastructure, Low Awareness
clear all
use pos_vol_level_high_infra_low_aware_did, clear

set obs `= _N + 1'
replace parm = "distcc_nt1" if parm == ""
replace label = "t = 0" if strpos(parm, "t0")
replace label = "1" if parm == "distcc_nt1"
replace label = "-" + label if strpos(parm, "nt")
foreach var of varlist estimate stderr min95 max95 { 
replace `var' = 0 if `var' == .
}

replace label = "0" if label == "t = 0"
destring label, force replace 
drop if label == .
sort label

label variable estimate "Demonetization Effect"
label variable min95 "Lower CI 95pc"
label variable max95 "Upper CI 95pc" 

twoway (connected estimate label, graphregion(color(white)) lc(navy) mc(navy)) ///
(rline min95 max95 label, lpattern(dot) lcolor(blue)), yline(0, lcolor(red)) ///
xline(-1, lcolor(solid) lpattern(dash)) xlabel(-3 0 3 6) ylabel(#3) ///
xtitle("") ytitle("Percent", height(5)) legend(off) ///
ylab(, nogrid) xlab(, nogrid) graphregion(margin(2 2 2 2)) subtitle("High Infrastructure" "Low Awareness")

graph save pos_vol_level_high_infra_low_aware_did.gph, replace

*Figure 8, High Infrastructure, High Awareness
clear all
use pos_vol_level_high_infra_high_aware_did, clear

set obs `= _N + 1'
replace parm = "distcc_nt1" if parm == ""
replace label = "t = 0" if strpos(parm, "t0")
replace label = "1" if parm == "distcc_nt1"
replace label = "-" + label if strpos(parm, "nt")
foreach var of varlist estimate stderr min95 max95 { 
replace `var' = 0 if `var' == .
}

replace label = "0" if label == "t = 0"
destring label, force replace 
drop if label == .
sort label

label variable estimate "Demonetization Effect"
label variable min95 "Lower CI 95pc"
label variable max95 "Upper CI 95pc" 

twoway (connected estimate label, graphregion(color(white)) lc(navy) mc(navy)) ///
(rline min95 max95 label, lpattern(dot) lcolor(blue)), yline(0, lcolor(red)) ///
xline(-1, lcolor(solid) lpattern(dash)) xlabel(-3 0 3 6) ylabel(#3) ///
xtitle("") ytitle("Percent", height(5)) legend(off) ///
ylab(, nogrid) xlab(, nogrid) graphregion(margin(2 2 2 2)) subtitle("High Infrastructure" "High Awareness")

graph save pos_vol_level_high_infra_high_aware_did.gph, replace

graph combine pos_vol_level_low_infra_low_aware_did.gph pos_vol_level_low_infra_high_aware_did.gph ///
pos_vol_level_high_infra_low_aware_did.gph pos_vol_level_high_infra_high_aware_did.gph, graphregion(color(white)) rows(2) 
graph export pos_vol_level_infra_aware_event.pdf, replace 


*Figure E7
clear all
use pos_terminal_did, clear

set obs `= _N + 1'
replace parm = "distcc_nt1" if parm == ""
replace label = "t = 0" if strpos(parm, "t0")
replace label = "1" if parm == "distcc_nt1"
replace label = "-" + label if strpos(parm, "nt")
foreach var of varlist estimate stderr min95 max95 { 
replace `var' = 0 if `var' == .
}

replace label = "0" if label == "t = 0"
destring label, force replace 
drop if label == .
sort label

*line estimate min95 max95 label, lpattern(l - - ) xline(0) yline(0)
*encode parm, generate(parm2)
*drop parm
*rename parm2 parm
label variable estimate "Demonetization Effect"
label variable min95 "Lower CI 95pc"
label variable max95 "Upper CI 95pc" 

twoway (connected estimate label, graphregion(color(white)) lc(navy) mc(navy)) ///
(rline min95 max95 label, lpattern(dot) lcolor(blue)), yline(0, lcolor(red)) ///
xline(-1, lcolor(solid) lpattern(dash)) xlabel(-3 0 3 6) ylabel(#3) ///
xtitle("") ytitle("Percent", height(5)) legend(off) ///
ylab(, nogrid) xlab(, nogrid) graphregion(margin(2 2 2 2)) subtitle("POS Terminals Per Capita" "Event Study")

graph save pos_terminals_did.gph, replace
graph export pos_terminals_did.png, replace
